<!DOCTYPE>
<html>
@include('common.head')
<body style="background-color: #fff !important">
<meta name="csrf-token" content="{{ csrf_token() }}">	
<div class="modelpact j-pactModel">
	<div class="row-fluid margin-bottom-25">
		<div class="span12">
			<!-- BEGIN VALIDATION STATES-->			
			<div class="portlet box gdcdc">
				<div class="portlet-body form">
					<!-- BEGIN FORM-->
					<form action="#" id="form_pactchose" class="form-horizontal padding-top-20">
						<input type="hidden" id="contract_order_id" value="{{$rs['contract_order_id']}}">
						<div class="control-group">
							<label class="control-label">合同类型<span class="required">*</span></label>
							<div class="controls">
								<select class="span9 m-wrap j-pactchoose" id="contract_type">
									<option value="">请选择合同</option>
									@foreach (config('order.order.contract_type') as $contract_type)
										<option @if (isset($rs['material']->contract_type) && $rs['material']->contract_type == $loop->index)selected="selected"@endif value="{{$loop->index}}">{{$contract_type}}</option>
									@endforeach
								</select>
							</div>
						</div>
						<div class="choosmind">
							<!--选择 “标准无价易制毒合同”-->
							<div class="opt-lessdrug" id="pressDrug">
								<div class="control-group">
									<label class="control-label"></label>
									<div class="controls">
										<div class="span9 m-wrap" >
											<div class="btn-group priblue">
												<a href="javascript:;" id="sample_downPact" class="">
												下载合同
												</a>
											</div>
										</div>
									</div>
								</div>
							</div>
							<!--选择 “标准有价易制毒合同”-->
							<div class="opt-lessdrug hide" id="pressDrug">
								<div class="control-group">
									<label class="control-label"></label>
									<div class="controls">
										<div class="span9 m-wrap" >
											<div class="prired">
												当前订单存在超额超级或低价，合同需要审核通过后才可以下载使用
											</div>
										</div>
									</div>
								</div>
							</div>
							<!--非标准有价易制毒合同-->
							<div class="opt-lessdrug hide" id="pressDrug">
								<div class="control-group">
									
								</div>
							</div>
							<!--单笔非标准合同-->
							<div class="opt-lessdrug hide" id="pressDrug">
								<div class="control-group">
									
								</div>
							</div>
							<!--选择 “单笔标准合同含附件条件”-->
							<div class="opt-lessdrug hide" id="pressDrug6"  data-id="6">
								<div class="control-group">
									<label class="control-label">填写附加条件<span class="required">*</span></label>
									<div class="controls">
										<input type="text" class="span9 m-wrap c-rake" autocomplete="off" name="frake" placeholder="填写附加条件">
										<div class="prired margin-top-10">
											该合同类型需要发起OA审核，审核通过后可以使用
										</div>
									</div>
								</div>
							</div>

							<div class="opt-contract @if (isset($rs['material']->contract) && $rs['material']->contract != '') hide @endif" id="upload_contract">
								<div class="control-group">
									<label class="control-label">上传合同<span class="required">*</span></label>
									<div class="uploader controls">
									    <input type="text" class="span7 twoupfile filename" name="twoupfile" readonly/>
									    <input type="button" name="file" class="button" value="上传..."/>
									    <div class="margin-top-10"></div>
									    <input id="ImportPicInput" class="button" type="file" size="30"/>
									    <div class="prired margin-top-10 hide" id="oa_msg">
											该合同类型需要发起OA审核，审核通过后可以使用
										</div>
									</div>
								</div>
							</div>
							
							<div class="opt-lessdrug @if (!isset($rs['material'])) hide @endif" id="down_contract">
								<div class="control-group">
									<label class="control-label">合同已上传</label>
									<div class="controls">
										<input type="hidden" id="contract_pic">
										@if (!isset($rs['material'])) 
											<img id="showPic" src="" org_pic="" class="upedimg">
										@else
											<img id="showPic" src="{{resizeImage('contract/'.$rs['material']->contract,'100','100')}}" org_pic="{{resizeImage('contract/'.$rs['material']->contract,'640','640')}}" class="upedimg">
										@endif
									    
									    <div class="m-wrap" >
											<div class="btn-group pertionblue">
												<a target="_blank_" href="javascript:;" id="down_pic" class="">
												下载合同
												</a>
											</div>
										</div>
									</div>
								</div>
							</div>
							
						</div>

						<div class="publay_butom">			
							<a href="javascript:;" onclick="javascript:update_contract();" class="laysure-btn0">确定</a>		
							<a onclick="closedHandler()" class="laycols-btn1">取消</a>		
						</div>	
					</form>
					<!-- END FORM-->
				</div>
			</div>
			<!-- END VALIDATION STATES-->
		</div>
	</div>
</div>

<script src="{{URL::asset('static/js/bootstrap/fileinput.min.js')}}"></script>
<link rel="stylesheet" href="{{URL::asset('static/style/bootstrap/fileinput.min.css')}}">
<script>
	//上传file自定义样式
	$(".uploader input[type=file]").change(function(){
		$(this).parents(".uploader").find(".filename").val($(this).val());
	});
	var update_contract = function(){
    	var contract_type = $("#contract_type").val();
    	var order_id = $("#contract_order_id").val();
    	var contract = $("#contract_pic").val();
    	var conditions = $.trim($(".c-rake").val())  // 附件条件值		
    	if(contract_type == ''){
    		layer.msg("请选择合同类型",{icon:2,time:1500});
    		return false;
    	}
    	if(contract_pic == ''){
    		layer.msg("请上传合同（是否点击UPLOAD?）",{icon:2,time:1500});
    		return false;
    	}
    	if(contract_type == 6){

    	}
    	// $.ajaxSetup({
	    //     headers: {
	    //         'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	    //     }
	    // });
    	$.ajax({
			url: "/order/ajaxUploadContract",
			type : "POST", 
			dataType :"json",
			data:'contract_type='+contract_type+'&order_id='+order_id+'&contract='+contract,
			success: function(data){
				if(data == 1){
					parent.location.reload();
				}
			},
           	error: function(data){
				layer.msg('ERROR!',{icon:2,time:1500});
			}
		});
    	// closedHandler();
    }
    function closedHandler(){
	var index = parent.layer.getFrameIndex(window.name);
	//刷新父层
	// parent.location.reload();
	//关闭弹出层
	parent.layer.close(index);
}

$(document).on("ready", function() {
	//选择合同弹窗（合同类型下拉框选择）02-对应内容显示 
	$(".j-pactchoose").on('change',function(){
		var i = $(this).find("option:selected").val();
		if($("#pressDrug"+i).length == 1){
			$("#pressDrug"+i).show().siblings(".opt-lessdrug").hide()
		}else{
			$(".opt-lessdrug").hide()
		}
		
	})
	$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $("#ImportPicInput").fileinput({
        uploadUrl: "/order/ajax_upload_contract_file",
        uploadAsync: true,
        browseClass: "btn file-primary",
        // allowedFileExtensions: ['jpg', 'png', 'gif'],
        // maxFileSize
        uploadExtraData: function(previewId, index) {
            return {order_id: $('#contract_order_id').val()};
        },
        showPreview: false,
        showCaption: false,
        maxFileCount: 1
    }).on('fileuploaded', function(e, params) {
    	
    	$("#upload_contract").hide();
    	$("#showPic").attr('src',params.response.small);
    	$("#showPic").attr('org_pic',params.response.big);
    	$("#contract_pic").val(params.response.v);
    	$("#down_pic").attr('href','/order/downpic?type=contract&id='+params.response.v);
    	$("#down_contract").show();
    });
    $("#showPic").click(function(){
		var pic = $(this).attr('org_pic');
		if(pic){
			var img = '<img src="'+pic+'" style="max-width:640px; max-height:640px" class="upedimg">';
			layer.open({
			  title:'查看',
			  type: 1,
			  // skin: 'layui-layer-demo', //样式类名
			  offset: 't',
			  closeBtn: 0, //不显示关闭按钮
			  anim: 5,
			  area: ['640px', '640px'], //宽高
			  shadeClose: true, //开启遮罩关闭
			  content: img
			});
		}
	});
});
</script>
</body>
</html>